﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<eCRAM.WebSite.Models.UserModel>" %>
<%@ Import Namespace="eCRAM.WebSite.Models" %>
<%@ Import Namespace="eCRAM.WebSite.Tools" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
<% if (Model.Id == Guid.Empty)
       Response.Write("eCram - Création d'un nouvel utilisateur");
   else
       Response.Write("eCram - Modification d'un utilisateur");
%>
	
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <%

    if (Model.Id == Guid.Empty)
        Response.Write("<h2>Création d'un nouvel utilisateur</h2>");
   else
        Response.Write("<h2>Modification d'un utilisateur</h2>");

        
        using (Html.BeginForm("ValidateUser", "ReferenceData", FormMethod.Post, new {Id = "FormUser"}))
        {%>
        <%:Html.ValidationSummary(true)%>
        
        <fieldset>
            <legend>Général</legend>
                <%:Html.HiddenFor(model => model.Id)%>
            
            <div class="editor-label">
                <%:Html.LabelFor(model => model.Login)%>
            </div>
            <div class="editor-field">
                <%:Html.TextBoxFor(model => model.Login)%>
                <%:Html.ValidationMessageFor(model => model.Login)%>
            </div>
            
            <div class="editor-label">
                <%:Html.LabelFor(model => model.FirstName)%>
            </div>
            <div class="editor-field">
                <%:Html.TextBoxFor(model => model.FirstName)%>
                <%:Html.ValidationMessageFor(model => model.FirstName)%>
            </div>
            
            <div class="editor-label">
                <%:Html.LabelFor(model => model.LastName)%>
            </div>
            <div class="editor-field">
                <%:Html.TextBoxFor(model => model.LastName)%>
                <%:Html.ValidationMessageFor(model => model.LastName)%>
            </div>
            
            <div class="editor-label">
                <%:Html.LabelFor(model => model.Company)%>
            </div>
            <div class="editor-field">
                <%:Html.TextBoxFor(model => model.Company)%>
                <%:Html.ValidationMessageFor(model => model.Company)%>
            </div>
            
            <div class="editor-label">
                <%:Html.LabelFor(model => model.IsActive)%>
            </div>
            <div class="editor-field">
                <%:Html.CheckBoxFor(model => model.IsActive)%>
                <%:Html.ValidationMessageFor(model => model.IsActive)%>
            </div>
            
            
            <div class="editor-label">
                <%:Html.LabelFor(model => model.Role)%>
            </div>
            <div class="editor-field">
                <%:Html.DropDownListFor(model => model.Role, ViewData.GetUserRoleList()) %>
                <%:Html.ValidationMessageFor(model => model.Role)%>
            </div>
            
            <div class="editor-label">
                <%:Html.LabelFor(model => model.Email)%>
            </div>
            <div class="editor-field">
                <%:Html.TextBoxFor(model => model.Email)%>
                <%:Html.ValidationMessageFor(model => model.Email)%>
            </div>

            <div class="editor-label">
                <%:Html.LabelFor(model => model.CreationDate)%>
            </div>
            <div class="editor-field">
                <%:Html.ReadOnlyTextBoxFor(model => model.CreationDate,
                                                      Model.CreationDate == DateTime.MinValue
                                                          ? ""
                                                          : Model.CreationDate.ToShortDateString())%>
                <%:Html.ValidationMessageFor(model => model.CreationDate)%>
            </div>
            
            
           
        </fieldset>
        
        <fieldset>
            <legend>Activités</legend>
            
            <%= Html.HiddenFieldsForValueObjectCollection("UserActivities", Model.UserActivities) %>

            <%

            if (Model.UserActivities != null && Model.UserActivities.Any())
            {
                var tableDescription = new TableDescription<UserActivityModel>();
                tableDescription.DeleteActionName = "DeleteUserActivity";
                tableDescription.HiddenFieldName = "idUserActivity";
                tableDescription.GetKeyMethod = item => item.Id;
                tableDescription.AddRow(new TableRowDescription<UserActivityModel>("Activité", item => item.ActivityLabel));
                
                Response.Write(Html.TableForItems(model => model.UserActivities, tableDescription, Model.UserActivities, "FormUser"));
            }
            else
            {
                Response.Write("Aucune activité n'est associée à l'utilisateur.<br /> <br />");
            }

            Response.Write(Html.DropDownList("idActivity", ViewData.GetNotHolidaysActivityList()));
            Response.Write(Html.HyperLink("AddUserActivity", "Ajouter", "FormUser"));
%>
        </fieldset>
         <p>
                <input type="submit" value="Sauvegarder" />
            </p>
    <%
        } %>

    <div>
        <%: Html.ActionLink("Retour", "SelectDataType", new {DataType = (int)EnumDataType.Utilisateurs}) %>
    </div>

</asp:Content>

